package com.xinzhidi.web.alarmSetting.controller;

import com.xinzhidi.common.annotation.Log;
import com.xinzhidi.common.core.controller.BaseController;
import com.xinzhidi.common.core.domain.AjaxResult;
import com.xinzhidi.common.core.domain.R;
import com.xinzhidi.common.core.page.TableDataInfo;
import com.xinzhidi.common.enums.BusinessType;
import com.xinzhidi.common.utils.poi.ExcelUtil;
import com.xinzhidi.web.alarmSetting.domain.AlarmSetting;
import com.xinzhidi.web.alarmSetting.domain.dto.AlarmSettingAddDto;
import com.xinzhidi.web.alarmSetting.domain.dto.AlarmSettingListDto;
import com.xinzhidi.web.alarmSetting.domain.dto.AlarmSettingUpdDto;
import com.xinzhidi.web.alarmSetting.domain.vo.AlarmSettingInfoVo;
import com.xinzhidi.web.alarmSetting.domain.vo.AlarmSettingListVo;
import com.xinzhidi.web.alarmSetting.service.AlarmSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 告警设置Controller
 *
 * @author ruoyi
 * @date 2023-05-31
 */
@RestController
@Api(tags = "告警设置")
@RequestMapping("/alarmSetting")
public class AlarmSettingController extends BaseController {
    @Autowired
    private AlarmSettingService alarmSettingService;

    @ApiOperation("查询告警设置列表")
    @PreAuthorize("@ss.hasPermi('alarmSetting:alarmSetting:list')")
    @PostMapping("/listAlarmSetting")
    public TableDataInfo<AlarmSettingListVo> listAlarmSetting(@Validated @RequestBody AlarmSettingListDto dto) {
        startPagePost(dto);
        return alarmSettingService.selectAlarmSettingList(dto);
    }

    @ApiOperation("查询告警设置下拉列表")
    @PreAuthorize("@ss.hasPermi('alarmSetting:alarmSetting:list')")
    @PostMapping("/listAlarmSettingSelect")
    public R<List<AlarmSetting>> listAlarmSettingSelect(@Validated @RequestBody AlarmSettingListDto dto) {
        return R.ok(alarmSettingService.listAlarmSettingSelect(dto));
    }

    @ApiOperation("导出告警设置列表")
    @PreAuthorize("@ss.hasPermi('alarmSetting:alarmSetting:export')")
    @Log(title = "告警设置", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAlarmSetting")
    public void exportAlarmSetting(HttpServletResponse response, AlarmSettingListDto dto) {
        TableDataInfo<AlarmSettingListVo> list = alarmSettingService.selectAlarmSettingList(dto);
        ExcelUtil<AlarmSettingListVo> util = new ExcelUtil<AlarmSettingListVo>(AlarmSettingListVo.class);
        util.exportExcel(response, list.getRows(), "告警设置数据");
    }

    @ApiOperation("获取告警设置详细信息")
    @PreAuthorize("@ss.hasPermi('alarmSetting:alarmSetting:query')")
    @GetMapping(value = "/getAlarmSettingById")
    public R<AlarmSettingInfoVo> getAlarmSettingById(@RequestParam("id") Long id) {
        return R.ok(alarmSettingService.selectAlarmSettingById(id));
    }

    @ApiOperation("新增告警设置") 
    @PreAuthorize("@ss.hasPermi('alarmSetting:alarmSetting:add')")
    @Log(title = "告警设置", businessType = BusinessType.INSERT)
    @PostMapping("addAlarmSetting")
    public AjaxResult addAlarmSetting(@Validated @RequestBody AlarmSettingAddDto dto) {
        return toAjax(alarmSettingService.insertAlarmSetting(dto));
    }

    @ApiOperation("修改告警设置")
    @PreAuthorize("@ss.hasPermi('alarmSetting:alarmSetting:edit')")
    @Log(title = "告警设置", businessType = BusinessType.UPDATE)
    @PostMapping("editAlarmSetting")
    public AjaxResult editAlarmSetting(@Validated @RequestBody AlarmSettingUpdDto dto) {
        return toAjax(alarmSettingService.updateAlarmSetting(dto));
    }

    @ApiOperation("删除告警设置")
    @PreAuthorize("@ss.hasPermi('alarmSetting:alarmSetting:remove')")
    @Log(title = "告警设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/delAlarmSetting")
    public AjaxResult delAlarmSetting(@RequestParam Long[] ids) {
        return toAjax(alarmSettingService.deleteAlarmSettingByIds(ids));
    }

    @ApiOperation("修改推送状态")
    @PreAuthorize("@ss.hasPermi('alarmSetting:alarmSetting:edit')")
    @Log(title = "修改推送状态", businessType = BusinessType.UPDATE)
    @GetMapping("editPushStatus")
    public AjaxResult editPushStatus(@ApiParam(value = "告警设置id")Long id , @ApiParam(value = "是否推送（0：是  1：否") String pushStatus) {
        return toAjax(alarmSettingService.editPushStatus(id , pushStatus));
    }





}
